<?php
/*
Template Name: reader wall
*/
?>
<?php get_header(); ?>
<div id="content">
  <p class="browse"> 你的位置：读者墙:</p>
  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <?php the_title('<h3>', '</h3>'); ?>
  <div class="entry">
      <?php the_content('More &raquo;'); ?>
	  <?php edit_post_link('编辑', '[ ', ' ]'); ?> 
  </div>
  <?php endwhile; ?>
<!-- 读者墙代码区(最好在此处加点注释文字,不然代码很多,新手容易混乱) -->
	<div>
	<?php
		 $query="SELECT COUNT(comment_ID) AS cnt, comment_author, comment_author_url, comment_author_email FROM (SELECT * FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->posts.ID=$wpdb->comments.comment_post_ID) WHERE user_id='0' AND comment_author_email != 'zhonghua0747@gmail.com' AND post_password='' AND comment_approved='1' AND comment_type='') AS tempcmt GROUP BY comment_author_email ORDER BY cnt DESC LIMIT 15";
		 //邮箱自己改下,最后的DESC LIMIT 39,39可以改成适合你主题宽度的数字,即显示的头像总数,并按评论数降序排列
	 
		$wall = $wpdb->get_results($query);
		 $maxNum = $wall[0]->cnt;
		 foreach ($wall as $comment)
		 {
			 $width = round(40 / ($maxNum / $comment->cnt),2);//此处是对应的血条的宽度
			 if( $comment->comment_author_url )
			 $url = $comment->comment_author_url;
			 else $url="#";
	  $avatar = get_avatar( $comment->comment_author_email, $size = '36', $default = get_bloginfo('wpurl').'/avatar/default.jpg' );
			 $tmp = "<li><a target=\"_blank\" href=\"".$comment->comment_author_url."\">".$avatar."<em>".$comment->comment_author."</em> <strong>+".$comment->cnt."</strong></br>".$comment->comment_author_url."</a></li>";
			 $output .= $tmp;
		  }
		 $output = "<ul class=\"readers-list\">".$output."</ul>";
		 echo $output ;
	?> 
	</div>
  <?php comments_template(); ?>
  <?php else : ?>
  <h2 class="center">Not Found</h2>
  <p class="center">对不起，没找到你感兴趣的内容啊，再试试看吧。。。</p>
  <?php include (TEMPLATEPATH . "/searchform.php"); ?>
  <?php endif; ?>  
<br/>

</div>
<!--end: content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

